﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FangDuShi_API.Common
{
    public class Fetch
    {
        #region 判断输入的字符串是否安全
        /// <summary>
        /// 判断输入的内容是否安全
        /// </summary>
        /// <param name="value"></param>
        /// <param name="chkType"></param>
        /// <returns></returns>
        public static string InspectData(string value, CheckGetEnum chkType)
        {
            bool isPass = false;
            switch (chkType)
            {
                default:
                    isPass = true;
                    break;
                case CheckGetEnum.Int:
                    {
                        try
                        {
                            int.Parse(value);
                            isPass = RegExp.IsNumeric(value);
                        }
                        catch
                        {
                            isPass = false;
                        }
                        break;
                    }
                case CheckGetEnum.Safety:
                    isPass = RegExp.IsSafety(value);
                    break;
                case CheckGetEnum.Decimal:
                    {
                        try
                        {
                            decimal.Parse(value);
                            isPass = RegExp.IsNumeric(value);
                        }
                        catch
                        {
                            isPass = false;
                        }
                        break;
                    }
            }
            if (!isPass)
            {
                return string.Empty;
            }
            return value;
        }
        #endregion
    }
}
